<template>
	<view class="container">
		<view class="wrapper">
			<!-- <view style="text-align: center;">
				<image src="../../static/logo.png" style="border-radius: 64upx;"></image>
			</view>
 -->
			<view class="input-content">
				<view class="cu-form-group"
					style="border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
					<view class="title">账号</view>
					<input type="text" v-model="user.account" placeholder="请输入账号" maxlength="11" data-key="phone"
						@input="inputChange" />
				</view>
				<view class="cu-form-group" style="border: 2upx solid whitesmoke;border-radius: 30px">
					<view class="title">密码</view>
					<input type="password" v-model="user.password" placeholder="请输入密码" maxlength="20"
						data-key="password" @input="inputChange" @confirm="toLogin" />
					<text class="send-msg" @click="forget">忘记密码</text>
				</view>
			</view>
			<button class="confirm-btn" @click="toLogin">登录</button>
			<button class="confirm-btn" @click="toLoginPhone">验证码登录</button>


			<view style="margin-top: 32px;text-align: center">
				<view><text style="color: #FFFFFF;font-size: 28upx;">没有账号？</text>
					<text style="color: #5E81F9" @click="register()">立即注册</text>
				</view>
			</view>
			<view class="footer">
				<text @tap="isShowAgree" class="cuIcon"
					:class="showAgree ? 'cuIcon-radiobox' : 'cuIcon-round'">同意</text>
				<!-- 协议地址 -->
				<navigator url="/my/setting/mimi" open-type="navigate" style="color: #5E81F9;">《隐私政策》</navigator>
				和
				<navigator url="/my/setting/xieyi" open-type="navigate" style="color: #5E81F9;">《用户服务协议》</navigator>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					account: '',
					password: ''
				},
				invitation: '',
				loginName: '',
				sending: false,
				sendTime: '获取验证码',
				count: 60,
				showAgree: false,
			}
		},
		onLoad() {

		},
		methods: {

			forget() {
				uni.navigateTo({
					url: '/pages/public/forgetPwd'
				});
			},
			register() {
				uni.navigateTo({
					url: '/pages/public/register'
				});
			},
			inputChange(e) {
				const key = e.currentTarget.dataset.key;
				this[key] = e.detail.value;
			},
			navBack() {
				uni.navigateBack();
			},
			isShowAgree() {
				//是否选择协议
				this.showAgree = !this.showAgree;
			},
			toLogin() {
				if (!this.showAgree) {
					uni.showToast({
						title: '请先同意用户协议',
						icon: "error"
					})
					return;
				} else if (!this.user.account) {
					uni.showToast({
						title: '请输入账号',
						icon: "error"
					});
				}
				// else if (this.user.phone.length != 11) {
				// 	uni.showToast({
				// 		title: '请输入正确的手机号',
				// 		icon: "error"
				// 	});
				// }
				else if (!this.user.password) {
					uni.showToast({
						title: '请输入密码',
						icon: "error"
					});
				} else {
					this.$myRequest({
						url: '/login/byPwd',
						data: this.user,
						method: 'post'
					}).then(r => {
						if (r.data.code == 200) {
							// 将用户id存储在本地缓存中
							let user = JSON.parse(r.data.data)
							console.log(user);
							uni.setStorageSync("userId", JSON.stringify(user.userId));

							// 如果用户是陪玩，则把陪玩认证，存储在本地缓存中
							if (user.authPW != undefined && user.authPW != null && user.authPW == 'y') {
								uni.setStorageSync("authPw", 'y');
							}

							uni.showToast({
								title: "登录成功",
								icon: "success"
							})
							// 返回首页，关闭所有页面以重新刷新
							uni.reLaunch({
								url: '/pages/index/index'
							})
						}
					});
				}
			},
			toLoginPhone() {
				uni.navigateTo({
					url: '/pages/public/loginphone'
				})
			}
		},

	}
</script>

<style lang='scss'>
	.send-msg {
		border-radius: 30px;
		color: black;
		background: white;
		height: 30px;
		font-size: 14px;
		line-height: 30px;
	}

	.container {
		top: 0;
		padding-top: 32upx;
		position: relative;
		width: 100%;
		height: 100%;
		overflow: hidden;
		background: #111224;
	}

	.wrapper {
		position: relative;
		z-index: 90;
		background: #111224;
		padding-bottom: 32upx;
	}


	.input-content {
		/* margin-top: 300upx; */
		/* padding-top: 300upx; */
		padding: 32upx 80upx;

	}


	.confirm-btn {
		width: 600upx;
		height: 80upx;
		line-height: 80upx;
		border-radius: 60upx;
		margin-top: 32upx;
		background: #5E81F9;
		color: #fff;
		font-size: 32upx;

		&:after {
			border-radius: 60px;
		}
	}

	.footer {
		padding-left: 140upx;
		margin-top: 32upx;
		text-align: center;
		display: flex;
		color: #FFFFFF;
	}


	.container {
		padding-top: 32upx;
		position: relative;
		width: 100%;
		height: 100%;
		overflow: hidden;
		background: #111224;
	}

	.wrapper {
		position: relative;
		z-index: 90;
		background: #111224;
		padding-bottom: 20px;
	}


	.input-content {
		padding: 32upx 80upx;
	}


	.confirm-btn {
		width: 600upx;
		height: 80upx;
		line-height: 80upx;
		border-radius: 60upx;
		margin-top: 32upx;
		background: #5E81F9;

		color: #fff;
		font-size: 32upx;

		&:after {
			border-radius: 60px;
		}
	}
</style>
